<template>
  <div>
    <p class="pinformation" style="margin-top: 7px">搜索条件</p>
    <el-form label-width="100px" :model="queryParams" ref="queryRef">
      <el-row>
        <el-col :span="5">
          <el-form-item label="方案编号：" prop="projectCode">
            <el-input
              v-model="queryParams.projectCode"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="方案名称：" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="方案类型：" prop="contractType">
            <el-select
              clearable
              v-model="queryParams.contractType"
              style="width: 100%"
              filterable
            >
              <el-option
                v-for="dict in proxy.addListNoLimit(sys_contract_type)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="加急状态：" prop="degree">
            <el-select clearable v-model="queryParams.degree" filterable>
              <el-option
                v-for="dict in proxy.addListNoLimit(sys_degree)"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">
          <el-form-item label="委托单位名称：" prop="wtCustomName">
            <el-input
              v-model="queryParams.wtCustomName"
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="受检单位名称：" prop="sjCustomName">
            <el-input
              v-model="queryParams.sjCustomName"
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="方案开始时间：">
            <el-date-picker
              v-model="dateRange"
              value-format="YYYY-MM-DD"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="方案状态：" prop="status">
            <el-input
              v-model="queryParams.status"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-row justify="end">
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="business resetBtn" @click="resetQuery"
              >重置</el-button
            >
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <p class="pinformation">方案列表</p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table ref="mainTableRef" :data="projectList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="projectCode" label="方案编号" align="center" />
      <el-table-column prop="projectName" label="方案名称" align="center" width="220"
        show-overflow-tooltip/>
      <el-table-column
        prop="sjCustomName"
        label="受检单位"
        align="center"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        prop="sjAddress"
        label="受检单位地址"
        align="center"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        prop="wtCustomName"
        label="委托单位"
        align="center"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column prop="planDate" label="计划开始时间" align="center" />
      <el-table-column prop="endTime" label="要求完成时间" align="center" />
      <el-table-column label="方案类型" align="center" width="130"
        show-overflow-tooltip>
        <template #default="scope">
          <dict-tag
            :options="sys_contract_type"
            :value="scope.row.contractType"
          />
        </template>
      </el-table-column>
      <el-table-column label="紧急类型" align="center">
        <template #default="scope">
          <dict-tag :options="sys_degree" :value="scope.row.degree" />
        </template>
      </el-table-column>
      <el-table-column prop="" label="当前状态" align="center" />
      <el-table-column prop="cyUserName" label="采样员" align="center" width="200"
        show-overflow-tooltip/>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template #default="scope">
          <el-button
            link
            type="success"
            @click="toProjectView(scope.row.projectId)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import { getCyUserList } from "@/api/cyCheck/cyReady";
const { proxy } = getCurrentInstance();
const {  sys_degree, sys_project_step } = proxy.useDict(
  "sys_degree",
  "sys_project_step"
);
const {
  sys_contract_type,
} = proxy.useOrgDict(
  "sys_contract_type",
);
const queryParams = ref({
  pageSize: 10,
  pageNum: 1,
  contractType: -1,
  degree: -1
});
const dateRange = ref([]);
const total = ref(0);
const projectList = ref([]);

function getList() {
  getCyUserList(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    (res) => {
      projectList.value = res.rows;
      total.value = res.total;
    }
  );
}

function handleQuery() {
  emit("toId", "");
  queryParams.pageNum = 1;
  getList();
}

function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

const emit = defineEmits(["toId"]);

function toProjectView(id) {
  emit("toId", id);
}

getList();

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 22 }];
    }
    getTableHeight();
  }
);
const heightParams = ref([{ tableName: "main", bottomHeight: 22 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
})

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});
</script>

<style></style>
